package com.allwees.support.fileservice.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sts.StsClient;

import java.util.Set;

@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "aws.config")
public class AwsConfig {

	public static final int DEFAULT_DURATION_SECONDS = 900;

	private String accessKeyId;

	private String accessKeySecret;

	private String region;

	private String roleArn;

	private String bucket;

	private String basePath;

	private Set<String> modules;

	@Bean
	public StsClient stsClient(){
		AwsBasicCredentials credentials = AwsBasicCredentials.create(accessKeyId, accessKeySecret);
		StaticCredentialsProvider provider = StaticCredentialsProvider.create(credentials);
		return StsClient.builder()
				.credentialsProvider(provider)
				.region(Region.of(region))
				.build();
	}
}
